const tools = require("./tools.js");
const protocal = require("./protocal.js");
process.stdin.on("data", (data) => {
  const req = JSON.parse(data);
  let result; // 存储执行工具的结果
  if (req.method === "tools/call") {
    // 说明是要调用工具
    result = tools[req.params.name](req.params.arguments);
  } else if (req.method in protocal) {
    result = protocal[req.method](req.params);
  } else {
    return;
  }

  const res = {
    jsonrpc: "2.0",
    result,
    id: req.id,
  };

  process.stdout.write(JSON.stringify(res) + "\n");
});
